home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Whack-A-Bill / source code / health.c < prev    next >
C/C++ Source or Header  |  1997-09-24  |  7KB  |  381 lines

  1. #include <qdoffscreen.h>
  2. #include "health.h"
  3.  
  4.  
  5. void SetBlood (void);
  6.  
  7. extern WindowPtr        gMainWindow;
  8. extern WindowPtr        gWindowTwo;
  9. extern GWorldPtr myOffGWorld;
  10. extern Boolean gDone;
  11.  
  12. int PlayerOneOldScore, PlayerTwoOldScore;
  13.  
  14. int PlayerOneHealth=10;
  15. int PlayerTwoHealth=10;
  16.  
  17. int PlayerOneScoreHealth;
  18. int PlayerTwoScoreHealth;
  19. extern Boolean gatesBlood;
  20. extern Boolean aronBlood;
  21.  
  22. Boolean gatesNextTime;
  23. Boolean aronNextTime;
  24.  
  25. void UpdateHealth(void)
  26. {
  27. Rect drawingRect;
  28. RGBColor foreColor, backColor;
  29.  
  30. PicHandle redSquare, graySquare;
  31.  
  32. redSquare=GetPicture(801);
  33. graySquare=GetPicture(800);
  34.  
  35. SetPort(gMainWindow);
  36.  
  37. foreColor.red=65535;
  38. foreColor.green=0;
  39. foreColor.blue=0;
  40.  
  41. backColor.red=65535;
  42. backColor.green=65535;
  43. backColor.blue=65535;
  44.  
  45. RGBForeColor(&foreColor);
  46. RGBBackColor(&backColor);
  47.  
  48.  
  49. if(PlayerOneHealth > 0)
  50.     {    
  51.             SetRect(&drawingRect,7,419,25,457);
  52.             DrawPicture(redSquare,&drawingRect);
  53.     }
  54. else
  55.     {
  56.             SetRect(&drawingRect,7,419,25,457);
  57.             DrawPicture(graySquare,&drawingRect);
  58.     }
  59.     
  60. if(PlayerOneHealth > 1)
  61.     {    
  62.             SetRect(&drawingRect,25,419,43,457);
  63.             DrawPicture(redSquare,&drawingRect);
  64.     }
  65. else
  66.     {
  67.             SetRect(&drawingRect,25,419,43,457);
  68.             DrawPicture(graySquare,&drawingRect);
  69.     }
  70.     
  71. if(PlayerOneHealth > 2)
  72.     {    
  73.             SetRect(&drawingRect,43,419,61,457);
  74.             DrawPicture(redSquare,&drawingRect);
  75.     }
  76. else
  77.     {
  78.             SetRect(&drawingRect,43,419,61,457);
  79.             DrawPicture(graySquare,&drawingRect);
  80.     }
  81.     
  82. if(PlayerOneHealth > 3)
  83.     {    
  84.             SetRect(&drawingRect,61,419,79,457);
  85.             DrawPicture(redSquare,&drawingRect);
  86.     }
  87. else
  88.     {
  89.             SetRect(&drawingRect,61,419,79,457);
  90.             DrawPicture(graySquare,&drawingRect);
  91.     }
  92.     
  93. if(PlayerOneHealth > 4)
  94.     {    
  95.             SetRect(&drawingRect,79,419,97,457);
  96.             DrawPicture(redSquare,&drawingRect);
  97.             gatesNextTime=true;
  98.     }
  99. else
  100.     {
  101.             SetRect(&drawingRect,79,419,97,457);
  102.             DrawPicture(graySquare,&drawingRect);
  103.             if(gatesNextTime)
  104.             {
  105.             gatesBlood=true;
  106.             SetBlood();
  107.             gatesNextTime=false;
  108.             }
  109.     }
  110. if(PlayerOneHealth > 5)
  111.     {    
  112.             SetRect(&drawingRect,97,419,115,457);
  113.             DrawPicture(redSquare,&drawingRect);
  114.     }
  115. else
  116.     {
  117.             SetRect(&drawingRect,97,419,115,457);
  118.             DrawPicture(graySquare,&drawingRect);
  119.     }
  120.     
  121. if(PlayerOneHealth > 6)
  122.     {    
  123.             SetRect(&drawingRect,115,419,133,457);
  124.             DrawPicture(redSquare,&drawingRect);
  125.     }
  126. else
  127.     {
  128.             SetRect(&drawingRect,115,419,133,457);
  129.             DrawPicture(graySquare,&drawingRect);
  130.     }
  131.  
  132. if(PlayerOneHealth > 7)
  133.     {    
  134.             SetRect(&drawingRect,133,419,151,457);
  135.             DrawPicture(redSquare,&drawingRect);
  136.     }
  137. else
  138.     {
  139.             SetRect(&drawingRect,133,419,151,457);
  140.             DrawPicture(graySquare,&drawingRect);
  141.     }
  142.  
  143. if(PlayerOneHealth > 8)
  144.     {    
  145.             SetRect(&drawingRect,151,419,169,457);
  146.             DrawPicture(redSquare,&drawingRect);
  147.     }
  148. else
  149.     {
  150.             SetRect(&drawingRect,151,419,169,457);
  151.             DrawPicture(graySquare,&drawingRect);
  152.     }
  153.     
  154. if(PlayerOneHealth > 9)
  155.     {    
  156.             SetRect(&drawingRect,169,419,187,457);
  157.             DrawPicture(redSquare,&drawingRect);
  158.     }
  159. else
  160.     {
  161.             SetRect(&drawingRect,169,419,187,457);
  162.             DrawPicture(graySquare,&drawingRect);
  163.     }
  164.  
  165.  
  166.  
  167. if(PlayerTwoHealth > 9)
  168.     {    
  169.             SetRect(&drawingRect,213,419,231,457);
  170.             DrawPicture(redSquare,&drawingRect);
  171.     }
  172. else
  173.     {
  174.             SetRect(&drawingRect,213,419,231,457);
  175.             DrawPicture(graySquare,&drawingRect);
  176.     }
  177.     
  178. if(PlayerTwoHealth > 8)
  179.     {    
  180.             SetRect(&drawingRect,231,419,249,457);
  181.             DrawPicture(redSquare,&drawingRect);
  182.     }
  183. else
  184.     {
  185.             SetRect(&drawingRect,231,419,249,457);
  186.             DrawPicture(graySquare,&drawingRect);
  187.     }
  188.     
  189. if(PlayerTwoHealth > 7)
  190.     {    
  191.             SetRect(&drawingRect,249,419,267,457);
  192.             DrawPicture(redSquare,&drawingRect);
  193.     }
  194. else
  195.     {
  196.             SetRect(&drawingRect,249,419,267,457);
  197.             DrawPicture(graySquare,&drawingRect);
  198.     }
  199.     
  200. if(PlayerTwoHealth > 6)
  201.     {    
  202.             SetRect(&drawingRect,267,419,285,457);
  203.             DrawPicture(redSquare,&drawingRect);
  204.     }
  205. else
  206.     {
  207.             SetRect(&drawingRect,267,419,285,457);
  208.             DrawPicture(graySquare,&drawingRect);
  209.     }
  210.     
  211. if(PlayerTwoHealth > 5)
  212.     {    
  213.             SetRect(&drawingRect,285,419,303,457);
  214.             DrawPicture(redSquare,&drawingRect);
  215.     }
  216. else
  217.     {
  218.             SetRect(&drawingRect,285,419,303,457);
  219.             DrawPicture(graySquare,&drawingRect);
  220.     }
  221. if(PlayerTwoHealth > 4)
  222.     {    
  223.             SetRect(&drawingRect,303,419,321,457);
  224.             DrawPicture(redSquare,&drawingRect);
  225.             aronNextTime=true;
  226.     }
  227. else
  228.     {
  229.             SetRect(&drawingRect,302,419,321,457);
  230.             DrawPicture(graySquare,&drawingRect);
  231.             if(aronNextTime)
  232.             {
  233.             aronBlood=true;
  234.             SetBlood();
  235.             aronNextTime=false;
  236.             }
  237.     }
  238.     
  239. if(PlayerTwoHealth > 3)
  240.     {    
  241.             SetRect(&drawingRect,321,419,339,457);
  242.             DrawPicture(redSquare,&drawingRect);
  243.     }
  244. else
  245.     {
  246.             SetRect(&drawingRect,321,419,339,457);
  247.             DrawPicture(graySquare,&drawingRect);
  248.     }
  249.  
  250. if(PlayerTwoHealth > 2)
  251.     {    
  252.             SetRect(&drawingRect,339,419,357,457);
  253.             DrawPicture(redSquare,&drawingRect);
  254.     }
  255. else
  256.     {
  257.             SetRect(&drawingRect,339,419,357,457);
  258.             DrawPicture(graySquare,&drawingRect);
  259.     }
  260.  
  261. if(PlayerTwoHealth > 1)
  262.     {    
  263.             SetRect(&drawingRect,357,419,375,457);
  264.             DrawPicture(redSquare,&drawingRect);
  265.     }
  266. else
  267.     {
  268.             SetRect(&drawingRect,357,419,375,457);
  269.             DrawPicture(graySquare,&drawingRect);
  270.     }
  271.     
  272. if(PlayerTwoHealth > 0)
  273.     {    
  274.             SetRect(&drawingRect,375,419,393,457);
  275.             DrawPicture(redSquare,&drawingRect);
  276.     }
  277. else
  278.     {
  279.             SetRect(&drawingRect,375,419,393,457);
  280.             DrawPicture(graySquare,&drawingRect);
  281.     }
  282. }
  283.  
  284.  
  285. void SetHealth(int PlayerOneScoreHealth, int PlayerTwoScoreHealth)
  286. {
  287.     if(PlayerTwoScoreHealth>(PlayerTwoOldScore+10))
  288.     {
  289.         PlayerOneHealth--;
  290.         PlayerTwoOldScore=PlayerTwoScoreHealth;
  291.         UpdateHealth();
  292.         if (PlayerOneHealth==0)
  293.             PlayerTwoWins();
  294.         if (PlayerOneHealth==5)
  295.             gatesBlood=true;
  296.     }
  297.     
  298.     
  299.     if(PlayerOneScoreHealth>(PlayerOneOldScore+10))
  300.     {
  301.         PlayerTwoHealth--;
  302.         PlayerOneOldScore=PlayerOneScoreHealth;
  303.         UpdateHealth();
  304.         if (PlayerTwoHealth==0)
  305.             PlayerOneWins();
  306.         if (PlayerTwoHealth==5)
  307.             aronBlood=true;
  308.     }
  309.     
  310. }
  311.  
  312. void PlayerOneWins(void)
  313. {
  314. PicHandle finalPicture;
  315. KeyMap keyMap;
  316. Rect finalRect;
  317. Boolean nextRound=false;
  318.  
  319. SetRect(&finalRect,0,0,320,210);
  320. finalPicture=GetPicture(3000);
  321. PlayerOneHealth=10;
  322. PlayerTwoHealth=10;
  323.         UpdateHealth();
  324. SetPort(gWindowTwo);
  325. DrawPicture(finalPicture,&finalRect);
  326. while(!((keyMap[1] >> 9) & 0x01))
  327.     GetKeys(keyMap);
  328. FlushEvents (everyEvent, 0);
  329. aronBlood=false;
  330. gatesBlood=false;
  331. LoadImages();
  332. }
  333.  
  334. void PlayerTwoWins(void)
  335. {
  336. PicHandle finalPicture;
  337. KeyMap keyMap;
  338. Rect finalRect;
  339. Boolean nextRound=false;
  340.  
  341. SetRect(&finalRect,0,0,320,210);
  342. finalPicture=GetPicture(3001);
  343. PlayerOneHealth=10;
  344. PlayerTwoHealth=10;
  345.         UpdateHealth();
  346. SetPort(gWindowTwo);
  347. DrawPicture(finalPicture,&finalRect);
  348. while(!((keyMap[1] >> 9) & 0x01))
  349.     GetKeys(keyMap);
  350. FlushEvents (everyEvent, 0);
  351. aronBlood=false;
  352. gatesBlood=false;
  353. LoadImages();
  354. }
  355.  
  356. void SetBlood (void)
  357. {
  358. PicHandle playerOnePict;
  359. PicHandle playerTwoPict;
  360. Rect ImageOneRect;
  361. Rect ImageTwoRect;
  362.  
  363. SetGWorld(myOffGWorld,nil);
  364.  
  365. SetRect(&ImageOneRect,0,0,640,210);
  366. SetRect(&ImageTwoRect,0,210,640,420);
  367.  
  368.  
  369. if(aronBlood)
  370. playerOnePict=GetPicture(668);
  371. else
  372. playerOnePict=GetPicture(667);
  373. if(gatesBlood)
  374. playerTwoPict=GetPicture(14);
  375. else
  376. playerTwoPict=GetPicture(13);
  377.  
  378. DrawPicture(playerOnePict,&ImageOneRect);
  379. DrawPicture(playerTwoPict,&ImageTwoRect);
  380. }
  381.